package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class CartController {

    @Autowired
    private CartService cartService;

    @PostMapping("/cart/add")
    public ResultInfo save(@RequestBody Cart cart){
        Cart cartForm=cartService.save(cart);
        return ResultInfo.success(cartForm);
    }
    @GetMapping("/cart/list")
    public ResultInfo cartList(){
        List<Cart> cartList=cartService.cartList();
        return ResultInfo.success(cartList);
    }
    @PostMapping("/cart/sub")
    public ResultInfo update(@RequestBody Cart cart){
        Cart cartFrom=cartService.update(cart);
        return ResultInfo.success(cartFrom);
    }
    @DeleteMapping("/cart/clean")
    public ResultInfo deleted(){
        cartService.deleted();
        return ResultInfo.success(null);
    }
}
